Approximating π By The Ratio of Areas

This is a unique way to approximate π by using the ratio of a circle's area and the area of the square it is inscribed in. If r is 1/2 of the side of a square then the formulas for the area of the square and the area of the inscribed circle are:

A = 4 r 2 A = π r 2

The areas of the circle and the square can be approximated by randomly choosing points within the square and determining which fall also in the circle. The ratio of those points that fall in the circle to the total number of points (i.e. those falling in the square) leads to our approximation of π.

A A = π r 2 4 r 2
4 A A = π

Enter the number of points for the calculator to return an approximation of π. Reload the page to clear previous run's dots.




Enter the number of points to be chosen and hit the button:






There is a bug in Safari's implementation of JavaScript. When the program is run for any limit greater than about 20,000 (after reloading the page) the answer provided is 3. For values close to this limit repeated runs will eventually start producing correct answers. For higher values (>100,000) the incorrect value is always shown. This behaviour is not seen when the debugger is open and is not seen in Firefox. This error was fixed in one of the many Safari updates between Jan 2018 and Oct 2019.